package dp;

public class numSquares {
    public int numSquares(int n) {
        int[] fn = new int[n+1];
        for(int i=1;i<=n;i++){
            int min = Integer.MAX_VALUE;
            for(int j=1;j*j<=i;j++){
                min=Math.min(min, fn[i-j*j]);
            }
            fn[i]=min+1;
        }
        return fn[n];
    }

    public static void main(String[] args) {

    }
}
